https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/


class Solution {
public:
    int strToInt(string str) {
       
        int i = 0;
        while(i < str.size() && str[i] == ' ') ++i;//跳过所有的空格
        long ret = 0;
        bool isminus = false; //假设正数
        if(str[i] == '-' || str[i] == '+'){
            if(str[i] == '-') isminus = true; //如果出现-号就标记为负数
            ++i;
        } 
        long long res = 0;
        while(str[i] >= '0' && str[i] <= '9'){
            ret = ret * 10 + str[i] - '0';  //将剩余的数字字符转换为数字
            ++i;
            if(!isminus && ret > INT_MAX) return INT_MAX;
            if(isminus && ret- 1 > INT_MAX) return INT_MIN; 
        }
        return isminus ? -ret : ret;
    }
};
